export default {
  tree_fp_sale_order: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.sale.order',
    type: 'tree',
    priority: 2,

    toolbar: {
      action: [
        {
          name: '创建发票',
          id: 'fp_sale.action_sale_to_fapiao',
          xml_id: 'fp_sale.action_sale_to_fapiao'
        }
      ]
    },

    fields: {
      client_order_ref: { string: 'NC发票PK' },
      name: {},
      date_order: {},
      partner_id: {},
      partner_invoice_id: {},
      amount_total: {},
      company_id: {},
      state: {}
    }
  },

  form_fp_sale_order: {
    _odoo_model: 'ir.ui.view',
    model: 'fp.sale.order',
    type: 'form',
    toolbar: {
      action: {},
      print: {}
    },

    arch: {
      header: {
        buttons: [
          {
            name: 'action_confirm',
            string: '确认',
            type: 'object',
            btn_type: 'primary',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'draft'
            }
          },

          {
            name: 'action_cancel',
            string: '取消',
            type: 'object',
            invisible: ({ record }) => {
              const { id: res_id, state } = record
              return !['draft', 'confirmed', 'done'].includes(state) || !res_id
            }
          },

          {
            name: 'action_draft',
            string: '重置为草稿',
            type: 'object',
            // states: 'cancel',
            invisible: ({ record }) => {
              const { state } = record
              return state !== 'cancel'
            }
          }
        ],

        fields: {
          state: {
            widget: 'statusbar',
            statusbar_visible: 'draft,confirmed,done'
          }
        }
      }
    },

    fields: {
      // state: { invisible: 1 },
      state: {},
      client_order_ref: { string: 'NC发票PK' },
      name: {},
      partner_id: { domain: [] },
      partner_invoice_id: { domain: [] },

      date_order: { string: '订单日期' },
      amount_total: {},

      line_ids: {
        widget: 'x2many_tree',
        views: {
          tree: {
            fields: {
              // name: {},
              sequence: {},
              product_categ_id: {},
              product_id: {},
              product_spec: {},
              uom_name: {},
              tax_ratio: {},
              quantity: {},
              price_unit: {},
              amount_discount: {},
              amount_untaxed: {},
              amount_tax: {},
              note: {}
            }
          },

          form: {
            fields: {
              name: {},
              sequence: {},
              taxpayer_categ_id: {},
              product_categ_id: {},
              product_id: { domain: [] },
              product_spec: {},
              uom_name: {},
              tax_id: { required: 0 },
              tax_ratio: {},
              quantity: {},
              price_unit: {},
              amount_discount: {},
              amount_untaxed: {},
              amount_tax: {},
              note: {}
            }
          }
        }
      }
    }
  },

  // search_fp_sale_order: {
  //   _odoo_model: 'ir.ui.view',
  //   model: 'fp.sale.order',
  //   type: 'search',
  //   arch: {
  //     fields: {
  //       // name: {
  //       //   string: '订单',
  //       //   filter_domain: self => {
  //       //     return [
  //       //       '|',
  //       //       '|',
  //       //       ['name', 'ilike', self],
  //       //       ['client_order_ref', 'ilike', self],
  //       //       ['partner_id', 'child_of', self]
  //       //     ]
  //       //   }
  //       // },
  //       // partner_id: { operator: 'child_of' },
  //       // user_id: {},
  //       // team_id: {},
  //       // order_line: {
  //       //   string: '产品',
  //       //   filter_domain: self => {
  //       //     return [['order_line.product_id', 'ilike', self]]
  //       //   }
  //       // },
  //       // analytic_account_id: {}
  //     },

  //     filters: {
  //       // group1: {
  //       //   my_sale_orders_filter: {
  //       //     string: '我的订单',
  //       //     domain: ({ env }) => {
  //       //       const uid = env.uid
  //       //       return [['user_id', '=', uid]]
  //       //     }
  //       //   }
  //       // },
  //       // group2: {
  //       //   draft: {
  //       //     string: '报价单',
  //       //     domain: [['state', 'in', ['draft', 'sent']]]
  //       //   },
  //       //   sales: {
  //       //     string: '销售订单',
  //       //     domain: [['state', 'in', ['sale', 'done']]]
  //       //   }
  //       // },
  //       // group3: {
  //       //   filter_create_date: { string: '创建日期', date: 'create_date' }
  //       // }
  //     }
  //   }
  // },

  action_fp_sale_order: {
    _odoo_model: 'ir.actions',
    name: '销售订单',
    type: 'ir.actions.act_window',
    res_model: 'fp.sale.order',
    // search_view_id: 'search_fp_sale_order',
    domain: [],
    context: {},
    views: {
      tree: 'tree_fp_sale_order',
      form: 'form_fp_sale_order'
    }
  }
}
